package com.wanxi.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class MyCollection {
    public static void main(String[] args) {
//        Collection<Integer> collection = new ArrayList();
        /**
         * 1.有基础或者实现
         * 2.由重写
         * 3.父类指向子类的引用
         */
//        collection.add(1);
        Collection<Student> arrayList = new ArrayList();
        arrayList.add(new Student("张三1", "aaa", "aaa", 1));
        arrayList.add(new Student("张三2", "aaa", "aaa", 1));
        Student student = new Student("张三3", "aaa", "aaa", 1);
//        arrayList.add(student);
        arrayList.add(new Student("张三4", "aaa", "aaa", 1));
        arrayList.add(new Student("张三4", "aaa", "aaa", 1));

//        arrayList.remove(student);

//        下界，上界：
//        Predicate<? super Student> predicate =new Predicate<Student>() {
//            @Override
//            public boolean test(Student student) {
//                return student.getName().equals("张三3");
//            }
//        } ;
//        arrayList.removeIf((aa)->aa.getName().equals("张三3"));
//        arrayList.removeIf(student1 -> student1.getName().equals("张三3"));
//        System.out.println(arrayList);
//        System.out.println(arrayList.size());
//        arrayList.clear();
//        System.out.println(arrayList.size());
//        System.out.println(arrayList.contains(student));
//        System.out.println(arrayList.isEmpty());
//        for (int i = 0; i < arrayList.size(); i++) {
//            System.out.println();
//        }
//        arrayList.forEach(new Consumer<Student>() {
//            @Override
//            public void accept(Student student) {
//                System.out.println(student);
//            }
//        });
//        arrayList.forEach(student1 -> System.out.println(student));
//        int i=arrayList.size();
//        while (i>=0){
//            System.out.println();
//            i--;
//        }
//        for (Student s:arrayList
//             ) {
//            System.out.println(s);
//        }
//        List<String> list=new ArrayList<>();
//        list.get(i)
        /**
         * 迭代器，一个一个迭代
         * 1.判断是否需要迭代，必须有东西（需求）
         * 2.每次迭代的内容：迭代日志：任务日志
         */
        Iterator<Student> iterator= arrayList.iterator();
        while (iterator.hasNext()){
            Student s=iterator.next();
            System.out.println(s);
        }
    }
}
